package com.mybatis.dao;

import com.mybatis.domain.Order;
import com.mybatis.domain.User;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface OrderDao {

    @Select("select * from orders where uid=#{id}")
    //被引用的方法
    List<Order> findById(int id);

    //一对一注解开发方法二
    @Select("select * from orders")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "ordertime", property = "ordertime"),
            @Result(column = "total", property = "total"),
            @Result(
                    property = "user",  //要封装的属性名称
                    javaType = User.class,  //要封装的实体类型
                    column = "uid",  //根据那个字段去查询user表的数据
                    //select属性 代表查询那个接口的方法获得数据
                    one = @One(select = "com.mybatis.dao.UserDao.findById")  //一对一注解
            )
    })
    List<Order> findAll();

    //一对一注解开发方法一
    /*@Select("select *,o.id oid from orders o join user u on o.uid=u.id")
    @Results({
            @Result(column = "oid", property = "id"),
            @Result(column = "ordertime", property = "ordertime"),
            @Result(column = "total", property = "total"),
            @Result(column = "uid", property = "user.id"),
            @Result(column = "username", property = "user.username"),
            @Result(column = "password", property = "user.password")
    })
    List<Order> findAll();*/

}
